package com.myk.game.ghosts;

import android.content.Context;
import com.myk.game.ghosts.databinding.ActivityMainBinding;
import com.myk.game.ghosts.interfaces.IMainController;
import com.myk.game.ghosts.pages.GamePage;
import com.myk.game.ghosts.pages.HomePage;
import com.myk.game.lib.BgMusicHelper;
import com.myk.game.lib.base.AbsBaseActivity;

public class MainActivity extends AbsBaseActivity<ActivityMainBinding> implements IMainController {

    //背景音乐开关状态
    private boolean bgMusicState;

    @Override
    protected void init() {
        bgMusicState = true;
        openBgMusic();
        jumpHomePage();
    }


    @Override
    public Context getContext() {
        return this;
    }

    @Override
    public void openBgMusic() {
        bgMusicState = true;
        if (BgMusicHelper.getInstance().isMusicPlaying()) {
            BgMusicHelper.getInstance().resumeMusic();
        }
        else {
            BgMusicHelper.getInstance().startMusic(this, R.raw.bg_music, true);
        }
    }

    @Override
    public void closeBgMusic() {
        bgMusicState = false;
        BgMusicHelper.getInstance().pauseMusic();
    }

    @Override
    public boolean isMusicPlaying() {
        return bgMusicState;
    }

    @Override
    public void jumpHomePage() {
        binding.flPageContainer.setPage(new HomePage(this));
    }

    @Override
    public void jumpGamePage() {
        binding.flPageContainer.setPage(new GamePage(this));
    }

}